package com.ts.camera2.Camera2Oes

import android.opengl.GLSurfaceView
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.ImageView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.ts.audiocamera.EGLActivity
import com.ts.audiocamera.R
import com.ts.camera2.camera.Camera2FrameCallback
import com.ts.camera2.camera.Camera2Wrapper

class CameraOesActivity : AppCompatActivity(), Camera2FrameCallback{
    var glSurfaceview:GLSurfaceView?=null
    var mCameraOSERender:CameraOSERender?=null


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_camera_oes)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }


        glSurfaceview=findViewById(R.id.oes_surface_view1)
        if (glSurfaceview==null){
            Log.e(TAG,"glSurfaceview11")
        }else{
            Log.e(TAG,"glSurfaceview22")
        }

        glSurfaceview?.setEGLContextClientVersion(2)
        mCameraOSERender=CameraOSERender(this,glSurfaceview)
        glSurfaceview?.setRenderer(mCameraOSERender)
        glSurfaceview?.renderMode = GLSurfaceView.RENDERMODE_WHEN_DIRTY

        findViewById<Button>(R.id.btn_start).setOnClickListener {
            startRecorder();

        }




    }

    override fun onDestroy() {
        super.onDestroy()
        mCameraOSERender?.stopRecord()
    }

    fun startRecorder(){
        mCameraOSERender?.startRecorder()
    }

    override fun onResume() {
        super.onResume()
//        if (mCameraOSERender?.surfaceTexture==null){
//            Log.e(TAG,"onResume")
//        }
//        mCamera2?.startCamera()

    }
    private  val TAG = "CameraOesActivity"

    override fun onPreviewFrame(data: ByteArray?, width: Int, height: Int) {
//        Log.e(TAG,"onPreviewFrame")
    }

    override fun onCaptureFrame(data: ByteArray?, width: Int, height: Int) {
//        Log.e(TAG,"onCaptureFrame")
    }
}